// core
import { createApp } from "vue"
// import "virtual:windi.css"
import App from "@/App.vue"
import store from "@/store"
import router from "@/router"
import "@/router/permission"
// qiankun

import { renderWithQiankun, qiankunWindow, QiankunProps } from "vite-plugin-qiankun/dist/helper"
// load
import { loadSvg } from "@/icons"
import { loadPlugins } from "@/plugins"
import { loadDirectives } from "@/directives"
// css
import "uno.css"
import "normalize.css"
import "element-plus/dist/index.css"
import "element-plus/theme-chalk/dark/css-vars.css"
import "vxe-table/lib/style.css"
import "vxe-table-plugin-element/dist/style.css"
import "@/styles/index.scss"
let app: any

// const app = createApp(App)

const bootstrap = (container: any) => {
  app = createApp(App)
  /** 加载插件 */
  loadPlugins(app)
  /** 加载全局 SVG */
  loadSvg(app)
  /** 加载自定义指令 */
  loadDirectives(app)
  app.use(store).use(router)
  if (container) {
    router.isReady().then(() => {
      app.mount("#appThree")
      // console.log("AAAAAAAAA23r32eqws：" + "querySelector", container.querySelector("#app"))
    })
    // app.mount("#app")
    // console.log(container.querySelector("#app"), app.mount("#app"), 'app.mount("#app")')
    // console.log("主应用传递的token：" + "querySelector")
  } else {
    router.isReady().then(() => {
      app.mount("#appThree")
    })
  }
}

const initQiankun = () => {
  renderWithQiankun({
    mount(props) {
      const { container, token } = props
      console.log("主应用传递的token：" + token)
      bootstrap(container)
    },
    bootstrap() {},
    unmount() {
      app.unmount()
    },
    update: function (props: QiankunProps): void | Promise<void> {
      throw new Error("Function not implemented.")
    }
  })
}
console.log(renderWithQiankun, "drenderWithQiankun")

qiankunWindow.__POWERED_BY_QIANKUN__ ? initQiankun() : bootstrap()

// app.use(store).use(router)
// router.isReady().then(() => {
//   app.mount("#app")
// })
